import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";

var _dec, _dec2, _dec3, _class;

import React from 'react';
import { Bind } from 'lodash-decorators';
import LeafMenuItemWrap from "./LeafMenuItemWrap";
import { getMenuKey } from "./utils";
import styles from "./styles.less?modules";
var LeafMenu = (_dec = Bind(), _dec2 = Bind(), _dec3 = Bind(), (_class = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(LeafMenu, _React$PureComponent);

  var _super = _createSuper(LeafMenu);

  function LeafMenu() {
    _classCallCheck(this, LeafMenu);

    return _super.apply(this, arguments);
  }

  _createClass(LeafMenu, [{
    key: "handleLeafMenuClick",
    value: function handleLeafMenuClick(leafMenu, subMenu) {
      var onClick = this.props.onClick;

      if (_isFunction(onClick)) {
        onClick(leafMenu, subMenu);
      }
    }
  }, {
    key: "handleLeafMenuMouseEnter",
    value: function handleLeafMenuMouseEnter(subMenu) {
      var onMouseEnter = this.props.onMouseEnter;

      if (_isFunction(onMouseEnter)) {
        onMouseEnter(subMenu);
      }
    }
  }, {
    key: "handleLeafMenuMouseLeave",
    value: function handleLeafMenuMouseLeave(subMenu) {
      var onMouseLeave = this.props.onMouseLeave;

      if (_isFunction(onMouseLeave)) {
        onMouseLeave(subMenu);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          menu = _this$props.menu,
          activeMenus = _this$props.activeMenus,
          getSubMenuStyle = _this$props.getSubMenuStyle,
          minHeight = _this$props.minHeight;
      var lineLen = menu.children.length - 1;

      if (menu.allChildrenAreOnlySubMenu) {
        return null;
      }

      return /*#__PURE__*/React.createElement("div", {
        className: [styles['leaf-menu'], 'cpaas-leaf-menu'].join(' '),
        style: _objectSpread(_objectSpread({}, getSubMenuStyle(menu)), {}, {
          minHeight: minHeight
        })
      }, menu.children.map(function (subMenu, index) {
        var isOnlySubMenu = subMenu.isOnlySubMenu;
        var prevSubMenu = menu.children[index - 1] || {
          isOnlySubMenu: false
        };
        var nextSubMenu = menu.children[index + 1] || {
          isOnlySubMenu: false
        };
        var prevSubMenuIsOnlySubMenu = prevSubMenu.isOnlySubMenu;
        var nextSubMenuIsOnlySubMenu = nextSubMenu.isOnlySubMenu;
        return /*#__PURE__*/React.createElement(React.Fragment, {
          key: getMenuKey(subMenu)
        }, /*#__PURE__*/React.createElement(LeafMenuItemWrap, {
          subMenu: subMenu,
          isLast: index >= lineLen,
          prevSubMenuIsOnlySubMenu: prevSubMenuIsOnlySubMenu,
          nextSubMenuIsOnlySubMenu: nextSubMenuIsOnlySubMenu,
          activeMenus: activeMenus,
          onClick: _this.handleLeafMenuClick,
          onMouseEnter: _this.handleLeafMenuMouseEnter,
          onMouseLeave: _this.handleLeafMenuMouseLeave
        }), index < lineLen && !isOnlySubMenu && /*#__PURE__*/React.createElement("div", {
          className: [styles['leaf-menu-item-wrap-line'], 'cpaas-leaf-menu-item-wrap-line'].join(' ')
        }));
      }));
    }
  }]);

  return LeafMenu;
}(React.PureComponent), (_applyDecoratedDescriptor(_class.prototype, "handleLeafMenuClick", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuClick"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleLeafMenuMouseEnter", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuMouseEnter"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleLeafMenuMouseLeave", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuMouseLeave"), _class.prototype)), _class));
export default LeafMenu;